package com.chunxuan.langquan.ui.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.androidkun.xtablayout.XTabLayout;
import com.chunxuan.langquan.R;
import com.chunxuan.langquan.base.BaseResult2;
import com.chunxuan.langquan.base.Config;
import com.chunxuan.langquan.base.Global;
import com.chunxuan.langquan.dao.http.APIRetrofit;
import com.chunxuan.langquan.support.util.GlideUtil;
import com.chunxuan.langquan.support.util.Logg;
import com.chunxuan.langquan.ui.activity.CourseDetailActivity;
import com.chunxuan.langquan.ui.adapter.CustomViewpager;
import com.ruitu.arad.api.RxUtil;
import com.ruitu.arad.base.BaseFragment;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.youth.banner.Banner;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

// 首页
public class Home1Fragment extends BaseFragment {
    //    private Banner banner;
    private static Home1Fragment fragment;
    private RelativeLayout rl_3,rl_search;// 精选文章,报告解读,下单,搜索
    private ImageView iv_notice;// 消息
    private TextView  vUnreadCount;

    public Home1Fragment() {

    }

    public static Home1Fragment newInstance() {
        if (fragment == null) {
            fragment = new Home1Fragment();
            Bundle args = new Bundle();
            fragment.setArguments(args);
        }
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_home1, container, false);
//        banner = v.findViewById(R.id.banner);// Banner布局
        rl_3 = v.findViewById(R.id.rl_3);
        iv_notice = v.findViewById(R.id.iv_notice);
//        tv_city = v.findViewById(R.id.tv_city);
        rl_search = v.findViewById(R.id.rl_search);
        vUnreadCount = v.findViewById(R.id.vUnreadCount);
        setListeners();
//        reqBannerList();// 请求banner列表
        return v;
    }

    private void setListeners() {
        setOnClickListener(rl_3,  iv_notice,  rl_search);
    }

    @Override
    public void onClick(View v) {
        if (v == rl_search) {// 搜索
//            startActivity(SearchActivity.class);
        }
        if (v == rl_3) {//
//            startActivity(ArticleListActivity.class);
        }
        if (v == iv_notice) {// 消息
            startActivity(CourseDetailActivity.class);
//            startActivityForResult(new Intent(getActivity(), MsgListActivity.class), 1001);
        }
    }

    // 请求首页banner
//    private Disposable reqBannerList() {
//        return APIRetrofit.getDefault().reqHomeBannerList("1")
//                .compose(RxUtil.<BaseResult2<List<Banner>>>subIoObMain())
//                .subscribe(new Consumer<BaseResult2<List<Banner>>>() {
//                    @Override
//                    public void accept(BaseResult2<List<Banner>> listBaseResult2) throws Exception {
//                        hideProgress();
//                        if (listBaseResult2.isSuccess()) {
//
//                        } else {
//
//                        }
//                        bannerList = listBaseResult2.getData();
//                        adapter.notifyDataSetChanged();
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        hideProgress();
//                        throwable.printStackTrace();
//                    }
//                });
//    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}